package com.jingbian.cppccbackend.controller.user;


import com.github.pagehelper.PageInfo;
import com.jingbian.cppccbackend.entity.Activities;
import com.jingbian.cppccbackend.entity.Result;
import com.jingbian.cppccbackend.entity.dto.ActivityCreateDTO;
import com.jingbian.cppccbackend.entity.dto.ActivityJoinedDTO;
import com.jingbian.cppccbackend.entity.dto.EnableActivityDTO;
import com.jingbian.cppccbackend.entity.dto.MyActivitiesDTO;

import com.jingbian.cppccbackend.service.user.IActivitiesService;
import com.jingbian.cppccbackend.utils.ResultUtil;
import com.jingbian.cppccbackend.vo.CanActivitiesVO;
import com.jingbian.cppccbackend.vo.CreateActivitiesVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author pum
 * @since 2025-02-27
 */
@RestController
@RequestMapping("/users/activities")
public class ActivitiesController {

  @Autowired
  private IActivitiesService activitiesService;

  /**
   * 创建新的活动
   * @param activityCreateDTO
   * @return Result<String>
   */
  @PostMapping("/create")
  public Result<String> createActivity(@RequestBody ActivityCreateDTO activityCreateDTO) {
       activitiesService.createActivity(activityCreateDTO);
       return ResultUtil.success("活动创建成功！");
  }

  /**
   * 查询我发起的活动
   * @param myActivitiesDTO
   */
  @PostMapping("/myActivity")
  public Result<PageInfo<Activities>> getMyActivities(@RequestBody MyActivitiesDTO myActivitiesDTO){
    return ResultUtil.success(activitiesService.selectMyActivity(myActivitiesDTO));
  }

  /**
   * 查询的我所发布的活动详情
   * @param aid
   * @return
   */
  @GetMapping("/activityDetail/{aid}")
  public Result<CreateActivitiesVO> getActivityDetail(@PathVariable Integer aid){
    CreateActivitiesVO createActivitiesVO = activitiesService.getActivities(aid);
    return ResultUtil.success(createActivitiesVO);
  }

  /**
   * 取消我发起的活动
   * @param aid
   * @return
   */
  @DeleteMapping("/cancelActivity")
  public Result<String> cancelActivity(@RequestParam Integer aid ,@RequestParam String status){
       if(!(status.equals("已提交") || status.equals("已驳回") || status.equals("已结束"))) {
          activitiesService.deleteActivity(aid);
          return  ResultUtil.success("删除成功！");
       }
       return ResultUtil.fail("删除失败！");
       }

  @PostMapping("/enableActivity")
  public Result<PageInfo<Activities>> getListenableActivities(@RequestBody EnableActivityDTO enableActivityDTO){
     return ResultUtil.success(activitiesService.getListEnableActivities(enableActivityDTO));
  }

  /**
   * 查询可参与的活动详情(含是否报名状态)
   * @param aid
   * @return
   */
  @GetMapping("/canActivityDetail/{aid}")
  public Result<CanActivitiesVO> getCanActivityDetail(@PathVariable Integer aid){
    CanActivitiesVO canActivitiesVO = activitiesService.getCanActivityDetail(aid);
    return ResultUtil.success(canActivitiesVO);
  }

  /**
   * 查询已经参与的活动列表
   */
  @PostMapping("/alreadyJoin")
  public Result<PageInfo<Activities>> getAlreadyJoin(@RequestBody ActivityJoinedDTO activityJoinedDTO){
    return ResultUtil.success(activitiesService.getAlreadyJoin(activityJoinedDTO));
  }
}
